export default {
    namespaced: true,
    state: {
        token: '',
    },
    getters: {},
    mutations: {
        // 更改token的值
        setToken(state,payload) {
            state.token = payload.value
        }
    },
    actions: {
        // 获取到token
        async getToken({commit}) {
            // 获取用户性息和微信临时凭据换取token
            // 1 获取用户信息
            const [err,resault] = await uni.getUserProfile({
                desc: '用于获取数据，来完成支付功能'
            })
            const {encryptedData,rawData,iv,signature} = resault
            console.log(102,err,resault);
            // 2 执行微信的登录 login 获取临时登录凭据
            const [err2, res2] = await uni.login();
            const { code } = res2;
            console.log(res2);

            // 3 换取token
            const {token} = await uni.$u.http.post('/users/wxlogin',{encryptedData,rawData,iv,signature,code})
            // console.log(112,token);
            commit('setToken',{value:token})
            // return token
        }
    }
}